package com.pb.wkflow.core.camunda.bpmn.instanceImpl;

import com.pb.wkflow.core.camunda.bpmn.instance.Participants;
import com.pb.wkflow.core.camunda.bpmn.instance.UserParticipant;
import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.model.bpmn.impl.instance.BpmnModelElementInstanceImpl;
import org.camunda.bpm.model.xml.ModelBuilder;
import org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext;
import org.camunda.bpm.model.xml.type.ModelElementTypeBuilder;
import org.camunda.bpm.model.xml.type.attribute.Attribute;

import static org.camunda.bpm.model.bpmn.impl.BpmnModelConstants.CAMUNDA_NS;

/**
 * @author 苗益辉
 * @date 2022/5/16 11:27
 */
@Slf4j
public class ParticipantsImpl  extends BpmnModelElementInstanceImpl implements Participants {

    /** 参数键或值 */
    protected static Attribute<String> idAttribute;
    /** 名称 */
    protected static Attribute<String> nameAttribute;
    /** 类型 */
    protected static Attribute<String> typeAttribute;

    public ParticipantsImpl(ModelTypeInstanceContext instanceContext) {
        super(instanceContext);
    }

    public static void registerType(ModelBuilder modelBuilder) {
        log.info("注册自定义用户节点参与者类型 Participants");
        ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(Participants.class, "participants")
                .namespaceUri(CAMUNDA_NS)
                .instanceProvider(new ModelElementTypeBuilder.ModelTypeInstanceProvider<Participants>() {
                    @Override
                    public Participants newInstance(ModelTypeInstanceContext instanceContext) {
                        return new ParticipantsImpl(instanceContext);
                    }
                });
        idAttribute = typeBuilder.stringAttribute("id").namespace(CAMUNDA_NS).build();
        nameAttribute = typeBuilder.stringAttribute("name").namespace(CAMUNDA_NS).build();
        typeAttribute = typeBuilder.stringAttribute("type").namespace(CAMUNDA_NS).build();
        typeBuilder.build();
    }


    @Override
    public String getId() {
        return idAttribute.getValue(this);
    }

    @Override
    public void setId(String id) {
        idAttribute.setValue(this, id);
    }

    @Override
    public String getName() {
        return nameAttribute.getValue(this);
    }

    @Override
    public void setName(String name) {
        nameAttribute.setValue(this, name);
    }

    @Override
    public String getType() {
        return typeAttribute.getValue(this);
    }

    @Override
    public void setType(String type) {
        typeAttribute.setValue(this, type);
    }
}
